

$(document).ready(function() {
	var verifyUrl = $('#code_img').attr("src");
	$('#code_img').click(function() {
		$(this).attr('src', verifyUrl + '?' + Math.random());
	});
});

function CheckField() {
	var nameStr = document.getElementById("reg_username").value;
	if (nameStr == '') {
		alert("用户名不能为空！");
		document.getElementById("reg_username").focus();
		return false;
	}
	if (nameStr.length > 20 || nameStr.length < 3) {
		alert("用户名长度不能小于3，并且不能大于20！");
		document.getElementById("reg_username").focus();
		return false;
	}
	for ( var nIndex = 0; nIndex < nameStr.length; nIndex++) {
		var cCheck = nameStr.charAt(nIndex);
		if (!(IsDigit(cCheck) || IsAlpha(cCheck) || cCheck == '_')) {
			alert("用户名只能使用字母、数字以及下划线，并且不能使用中文！");
			document.getElementById("reg_username").focus();
			return false;
		}
	}
	var passwordStr = document.getElementById("reg_password").value;
	if (passwordStr == '') {
		alert("用户密码不能为空！");
		document.getElementById("reg_password").focus();
		return false;
	}
	if (passwordStr.length > 14 || passwordStr.length < 6) {
		alert("密码长度长度不能小于6，并且不能大于14！");
		document.getElementById("reg_password").focus();
		return false;
	}
	var passwordStr2 = document.getElementById("reg_password2").value;
	if (passwordStr != passwordStr2) {
		alert("两次密码输入不一致！");
		document.getElementById("reg_password2").focus();
		return false;
	}
	
	var email = document.getElementById("reg_email").value;
	if (email == '') {
		alert("邮箱地址不能为空！");
		document.getElementById("reg_email").focus();
		return false;
	}
	var email2 = document.getElementById("reg_email2").value;
	if (email != email2) {
		alert("两次邮箱地址输入不一致！");
		document.getElementById("reg_email2").focus();
		return false;
	}
	if (!IsEmailAddress(email)) {
		alert("邮箱地址格式错误！");
		document.getElementById("reg_email").focus();
		return false;
	}
	var qq = document.getElementById("reg_qq").value;
	if (email == '') {
		alert("QQ号码不能为空！");
		document.getElementById("reg_qq").focus();
		return false;
	}
	var checkcode = document.getElementById("code").value;
	if (checkcode == '') {
		alert("验证码不能为空！");
		document.getElementById("code").focus();
		return false;
	}
	return true;
}

function ChangPwd() {
	var nameStr = document.getElementById("username").value;
	if (nameStr == '') {
		alert("用户名不能为空！");
		document.getElementById("username").focus();
		return false;
	}
	if (nameStr.length > 50 || nameStr.length < 1) {
		alert("用户名错误！");
		document.getElementById("username").focus();
		return false;
	}
	for ( var nIndex = 0; nIndex < nameStr.length; nIndex++) {
		var cCheck = nameStr.charAt(nIndex);
		if (!(IsDigit(cCheck) || IsAlpha(cCheck) || cCheck == '_')) {
			alert("用户名错误！");
			document.getElementById("username").focus();
			return false;
		}
	}
	var oldpasswordStr = document.getElementById("old_password").value;
	if (oldpasswordStr == '') {
		alert("旧密码不能为空！");
		document.getElementById("old_password").focus();
		return false;
	}
	if (oldpasswordStr.length > 16 || oldpasswordStr.length < 6) {
		alert("旧密码错误！");
		document.getElementById("old_password").focus();
		return false;
	}
	var passwordStr = document.getElementById("new_password").value;
	if (passwordStr == '') {
		alert("用户密码不能为空！");
		document.getElementById("new_password").focus();
		return false;
	}
	if (passwordStr.length > 16 || passwordStr.length < 6) {
		alert("密码长度长度不能小于6，并且不能大于16！");
		document.getElementById("new_password").focus();
		return false;
	}
	var passwordStr2 = document.getElementById("new_password2").value;
	if (passwordStr != passwordStr2) {
		alert("两次密码输入不一致！");
		document.getElementById("new_password2").focus();
		return false;
	}
	var checkcode = document.getElementById("code").value;
	if (checkcode == '') {
		alert("验证码不能为空！");
		document.getElementById("code").focus();
		return false;
	}
	return true;
}

function ChangPayPwd() {
	var nameStr = document.getElementById("username").value;
	if (nameStr == '') {
		alert("用户名不能为空！");
		document.getElementById("username").focus();
		return false;
	}
	if (nameStr.length > 50 || nameStr.length < 1) {
		alert("用户名错误！");
		document.getElementById("username").focus();
		return false;
	}
	for ( var nIndex = 0; nIndex < nameStr.length; nIndex++) {
		var cCheck = nameStr.charAt(nIndex);
		if (!(IsDigit(cCheck) || IsAlpha(cCheck) || cCheck == '_')) {
			alert("用户名错误！");
			document.getElementById("username").focus();
			return false;
		}
	}
	var oldpasswordStr = document.getElementById("old_pay_password").value;
	if (oldpasswordStr == '') {
		alert("旧密码不能为空！");
		document.getElementById("old_pay_password").focus();
		return false;
	}
	if (oldpasswordStr.length > 16 || oldpasswordStr.length < 6) {
		alert("旧密码错误！");
		document.getElementById("old_pay_password").focus();
		return false;
	}
	var passwordStr = document.getElementById("new_pay_password").value;
	if (passwordStr == '') {
		alert("用户密码不能为空！");
		document.getElementById("new_pay_password").focus();
		return false;
	}
	if (passwordStr.length > 16 || passwordStr.length < 6) {
		alert("密码长度长度不能小于6，并且不能大于16！");
		document.getElementById("new_pay_password").focus();
		return false;
	}
	var passwordStr2 = document.getElementById("new_pay_password2").value;
	if (passwordStr != passwordStr2) {
		alert("两次密码输入不一致！");
		document.getElementById("new_pay_password2").focus();
		return false;
	}
	var checkcode = document.getElementById("code").value;
	if (checkcode == '') {
		alert("验证码不能为空！");
		document.getElementById("code").focus();
		return false;
	}
	return true;
}



function GetPwd() {
    var nameStr = document.getElementById("username").value;
    if (nameStr == '') {
        alert("用户名不能为空！");
        document.getElementById("username").focus();
        return false;
    }
    if (nameStr.length > 50 || nameStr.length < 1) {
        alert("用户名错误！");
        document.getElementById("username").focus();
        return false;
    }
    for (var nIndex = 0; nIndex < nameStr.length; nIndex++) {
        var cCheck = nameStr.charAt(nIndex);
        if (!(IsDigit(cCheck) || IsAlpha(cCheck) || cCheck == '_')) {
            alert("用户名错误！");
            document.getElementById("username").focus();
            return false;
        }
    }
    var email = document.getElementById("email").value;
    if (email == '') {
        alert("邮箱地址不能为空");
        document.getElementById("email").focus();
        return false;
    }
    if (!IsEmailAddress(email)) {
    	alert("邮箱格式错误！");
        document.getElementById("email").focus();
        return false;
    }
    var checkcode = document.getElementById("code").value;
    if (checkcode == '') {
        alert("验证码不能为空！");
        document.getElementById("code").focus();
        return false;
    }
    
    return true;
}

var curWwwPath=window.document.location.href; 
var pathName=window.document.location.pathname; 
var pos=curWwwPath.indexOf(pathName); 
var locationPath =curWwwPath.substring(0,pos); 
$(document).ready(function(){
	// 用户名
	$("input#reg_username").blur(function(){
			var username= $("input#reg_username").val();
  			$.ajax(  
               {  
                   url:locationPath+'/index.php/Home/User/checkregister',  
                   type:"post",  
                   data:{'username':username},  
                   error:function(){alert(id_netword_error);},  
                   success:function(data){ 
                  	 	if(data==2){
                        	alert("用户名：("+username+")已经存在，请修改");
                        }else{
                        }
                   }  
               } 
           );
           
  });
	
	$("input#reg_password").blur(function(){
		var reg_password1= $("input#reg_password").val();
		if(reg_password1.length<4||reg_password1.length>14){
			alert("密码长度不符合，请修改!");
		}
	});
	
	$("input#reg_password2").blur(function(){
		var reg_password2= $("input#reg_password2").val();
		var reg_password1= $("input#reg_password").val();
		if(reg_password2.length<4||reg_password2.length>14){
			alert("再次输入密码长度不符合，请修改!");
		}
		if(reg_password2!=reg_password1){
			alert("再次输入密码与密码填写不相同，请修改!");
		}
	});

	$("input#reg_email").blur(function(){
		var reg_email= $("input#reg_email").val();
		var reg_em_gs=/^([a-zA-Z0-9]+[_|\-|\.]?)*[a-zA-Z0-9]+@([a-zA-Z0-9]+[_|\-|\.]?)*[a-zA-Z0-9]+\.[a-zA-Z]{2,3}$/;
        if(!reg_em_gs.test(reg_email))
        {
        	alert("邮箱填写格式不正确，请修改!");
        }
	}); 
	
	$("input#reg_email2").blur(function(){
	var reg_email2= $("input#reg_email2").val();
	var reg_email1= $("input#reg_email").val();
	var reg_em_gs=/^([a-zA-Z0-9]+[_|\-|\.]?)*[a-zA-Z0-9]+@([a-zA-Z0-9]+[_|\-|\.]?)*[a-zA-Z0-9]+\.[a-zA-Z]{2,3}$/;
    if(!reg_em_gs.test(reg_email2))
    {
    	alert("重复填写邮箱格式不正确，请修改!");
    }
	if(reg_email2!=reg_email1){
		alert("重复电子邮箱与邮箱填写不相同，请修改!");
		}
	});
	
	$("input#qq").blur(function(){
		var qq= $("input#qq").val();
		var reg_em_gs=/^[1-9][0-9]{4,9}$/;
	    if(!reg_em_gs.test(qq))
	    {
	    	alert("qq格式不正确，请修改!");
	    }
	});
	
	//在输入验证码的时候统一给提示
	$("input#code").blur(function(){
		
		
		
	});
	
	
	// 用户名
	$("input#agent_username").blur(function(){
			var username= $("input#agent_username").val();
  			$.ajax(  
               {  
                   url:locationPath+'/index.php/Home/User/checkr_agent_egister',  
                   type:"post",  
                   data:{'username':username},  
                   error:function(){alert(id_netword_error);},  
                   success:function(data){ 
                  	 	if(data==2){
                        	alert("代理账号：("+username+")已经存在，请修改");
                        }else{
                        }
                   }  
               } 
           );
  });
	
});
